<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>开心E城</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <!-- <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> -->
        <link rel="stylesheet" href="/static/admin/css/font.css">
        <link rel="stylesheet" href="/static/admin/css/xadmin.css">
        <script src="/static/admin/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="/static/admin/js/xadmin.js"></script>
        <link rel="stylesheet" href="/static/admin/lib/bootstrap/bootstrap.min.css">   
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="x-nav">
        	<b>{$title}</b>
          	<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5" action="{:url('backstage/ad/index')}">
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" name="name"  placeholder="请输入名称" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-input-inline">
                                  <select name="ad_position_id" lay-filter="" lay-verify="">
                                    <option value="">选择位置</option>
                                    {volist name='AdPosition' id='vo'}
                                    <option value="{$vo.id}">{$vo.name}</option>
                                    {/volist}
                                  </select>
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn" onclick="xadmin.open('添加','{:url(\'backstage/ad/form\')}',700,500)"><i class="layui-icon"></i>添加</button>
                        </div>
                        <div class="layui-card-body ">
                            <table class="table table-bordered">
                            <thead>
	                            <tr>
	                              	<th class="text-center">编号</th>
	                                <th class="text-center">位置</th>
	                                <th class="text-center">媒体类型</th>
	                                <th class="text-center">名称</th>
	                                <th class="text-center">链接</th>
	                                <th class="text-center">图片</th>
	                                <th class="text-center">内容描述</th>
	                                <th class="text-center">状态</th>
	                                <th class="text-center">创建时间</th>
	                                <th class="text-center">操作</th>
	                            </tr>
                            </thead>
                            <tbody>
                            	{volist name='list' id='vo'}
                            	<tr>
              									<td class="text-center">{$vo.id}</td>
              									<td class="text-center">{$vo.position_name}</td>
              									<td class="text-center">{$vo.media_type}</td>
              									<td class="text-center">{$vo.name}</td>
              									<td class="text-center">{$vo.link}</td>
              									<td class="text-center">
              										<img src="{$vo.image_url}" alt="" style="height: 80px;">
              									</td>
              									<td class="text-center">{$vo.content}</td>
              									<td class="text-center td-status">
                                  {if $vo.enabled eq 1}
                                  <span style="color: green;">使用中</span>
                                  {else /}
                                  <span style="color: red;">已禁用</span>
                                  {/if}
                                </td>
              									<td class="text-center">{$vo.end_time|date='Y-m-d H:i:s'}</td>
              									<td class="text-center">
              										<a href="javascript:;" onclick="xadmin.open('修改','{:url(\'backstage/ad/form\')}?id={$vo.id}',700,500)">修改</a>
                                  {if $vo.enabled eq 1}
                                  <span>|</span>
                                  <a href="javascript:;" onclick="stop(this,{$vo.id})" status="0">禁用</a>
                                  {else /}
                                  <span>|</span>
                                  <a href="javascript:;" onclick="stop(this,{$vo.id})" status="1">启用</a>
                                  {/if}
                                  <span>|</span>
                                  <a href="javascript:;" onclick="del(this,{$vo.id})">删除</a>
              									</td>
              								</tr>
                            	{/volist}
                            </tbody>
                          </table>
                        </div>
                        <div class="layui-card-body ">
                            <div class="page">
                                <div>
									               {$list|raw}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div> 
    </body>
    <script>
      layui.use(['laydate','form'], 
      function(){
        var laydate = layui.laydate;
        var form = layui.form;

      });

       /*禁用-启用*/
      function stop(obj,id){
        var status = $(obj).attr('status');
          layer.confirm('确认要操作吗？',function(index){
            $.ajax({
              url:'{:url("backstage/ad/enabled")}',
              type:'get',
              dataType:'json',
              data:'id=' + id + '&status=' + status,
              success: res => {
                if (res.code == 1) {
                  if (status == 1) {
                    $(obj).attr('title', '1')
                    $(obj).html('启用');
                    $(obj).parents("tr").find(".td-status").html('<span style="color: red;">已禁用</span>');
                  } else {
                    $(obj).attr('title', '0')
                    $(obj).html('禁用');
                    $(obj).parents("tr").find(".td-status").html('<span style="color: green;">使用中</span>');
                  }
                  layer.msg(res.msg,{icon: 6,time:1000});
                } else {
                  layer.msg(res.msg,{icon: 5,time:1000});
                }
              }
            });
          });
          return false;
      }

      function del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
              url:'{:url("backstage/ad/delAd")}',
              type:'get',
              dataType:'json',
              data:'id=' + id,
              success: res => {
                if (res.code == 1) {
                  $(obj).parents("tr").remove();
                  layer.msg(res.msg, {icon:1, time:1000});
                } else {
                  layer.msg(res.msg, {icon:2, time:1000});
                }
              }
            });
            
        });
        return false;
      }
    </script>
</html>